// components/song-menus-card/index.js
import { getSongsMenuDetail } from '../../service/api_music'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    cardId: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    cardData: {},
    songList: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 点击卡片
    handleClickCard() {
      wx.navigateTo({
        url: '/pages/song-menu-list/index?id=' + this.properties.cardId,
      })
    }
  },
  observers: {
    'cardId': function(val) {
      // 若没有传值，退出
      if(!val) return 
      // 根据id获取歌单详情
      getSongsMenuDetail(val).then(res => {
        this.setData({ cardData: res.playlist, songList: res.playlist.tracks.slice(0, 4) })
      })
    }
  }
})
